<?php
/**
 *　Service
 *
 * $Id: Service.php$
 */

class Service {

    /**
     *  _instances
     *  service对象集合
     *
     *  @var object
     */
    static private $_instances = array();

    /**
     * &factory
     * 实例化一个service
     * @param  string $serviceName service类名
     * @param  array $constructorParams Service构造参数
     * @return object
     */
    public static function factory($serviceName, $constructorParams = array()) {

        // 根据实现类检查是否已经factory过
        if (!isset(self::$_instances[$serviceName])) {
            self::$_instances[$serviceName] = new $serviceName($constructorParams);
        }

        return self::$_instances[$serviceName];
    }

}
